﻿/*********************
 *      INCLUDES
 *********************/
#include "lv_cubic_gui.h"
#include "images.h"
#include "images/coolflyreg_head.h"
#include "lv_port_indev.h"

// lv_obj_t* scrInit;
lv_obj_t* scr1 = NULL;
lv_obj_t* scr2 = NULL;
lv_obj_t* scr3 = NULL;
lv_obj_t* scr4 = NULL;
lv_obj_t* scr5 = NULL;
lv_obj_t* scr6 = NULL;

lv_obj_t* scrs[scrs_count];

lv_obj_t* lbl_cityname = NULL;
lv_obj_t* lbl_weather = NULL;
lv_obj_t* lbl_weather_unit = NULL;
lv_obj_t* lbl_bili_name = NULL;
lv_obj_t* lbl_bili_fans = NULL;
lv_obj_t* labe6 = NULL;
lv_obj_t* labe7 = NULL;
lv_obj_t* labe8 = NULL;
lv_obj_t* labe9 = NULL;
lv_obj_t* labe10 = NULL;
lv_font_declare(lv_font_montserrat_20);
lv_font_declare(lv_font_montserrat_24);
lv_font_declare(lv_font_montserrat_40);

bool inited = false;

static lv_group_t* g;
static lv_obj_t* tv;
static lv_obj_t* t1;
static lv_obj_t* t2;
static lv_obj_t* t3;


void lv_holo_cubic_gui(const char* weachern, const char* fens, const char* cityname2, uint32_t freeHeap)
{
	static lv_style_t default_style;
	static lv_style_t label_style;
	static lv_style_t label_style2;
	static lv_style_t label_style3;
	static lv_style_t label_style4;
	if (!inited) {
		inited = true;
		lv_style_init(&default_style);
		lv_style_set_bg_color(&default_style, LV_STATE_DEFAULT, LV_COLOR_BLACK);
		lv_style_set_bg_color(&default_style, LV_STATE_PRESSED, LV_COLOR_GRAY);
		lv_style_set_bg_color(&default_style, LV_STATE_FOCUSED, LV_COLOR_BLACK);
		lv_style_set_bg_color(&default_style, LV_STATE_FOCUSED | LV_STATE_PRESSED, lv_color_hex(0xf88));
		lv_obj_add_style(lv_scr_act(), LV_BTN_PART_MAIN, &default_style);
	}


	int scr_count = 0;
	if (!scr1) { // 天气
		scr1 = lv_scr_act();//在第一页创建
		scrs[scr_count++] = scr1;
		lv_obj_t* img1 = lv_img_create(scr1, NULL);
		lv_img_set_src(img1, &tianqi);
		lv_obj_align(img1, NULL, LV_ALIGN_OUT_TOP_MID, 0, 160);

		lv_style_init(&label_style);
		lv_style_set_text_opa(&label_style, LV_STATE_DEFAULT, LV_OPA_COVER);
		lv_style_set_text_color(&label_style, LV_STATE_DEFAULT, LV_COLOR_WHITE);
		lv_style_set_text_font(&label_style, LV_STATE_DEFAULT, &lv_font_montserrat_24);
		lbl_cityname = lv_label_create(scr1, NULL);
		lv_obj_add_style(lbl_cityname, LV_LABEL_PART_MAIN, &label_style);
		lv_label_set_text(lbl_cityname, cityname2);
		lv_obj_align(lbl_cityname, NULL, LV_ALIGN_OUT_BOTTOM_LEFT, 25, -65);


		lv_style_init(&label_style2);
		lv_style_set_text_opa(&label_style2, LV_STATE_DEFAULT, LV_OPA_COVER);
		lv_style_set_text_color(&label_style2, LV_STATE_DEFAULT, LV_COLOR_WHITE);
		lv_style_set_text_font(&label_style2, LV_STATE_DEFAULT, &lv_font_montserrat_40);
		lbl_weather = lv_label_create(scr1, NULL);
		lv_obj_add_style(lbl_weather, LV_LABEL_PART_MAIN, &label_style2);
		lv_label_set_text(lbl_weather, weachern);
		lv_obj_align(lbl_weather, lbl_cityname, LV_ALIGN_OUT_RIGHT_MID, 10, 0);

		lv_style_init(&label_style3);
		lv_style_set_text_opa(&label_style3, LV_STATE_DEFAULT, LV_OPA_COVER);
		lv_style_set_text_color(&label_style3, LV_STATE_DEFAULT, LV_COLOR_WHITE);
		lv_style_set_text_font(&label_style3, LV_STATE_DEFAULT, &lv_font_montserrat_24);
		lbl_weather_unit = lv_label_create(scr1, NULL);
		lv_obj_add_style(lbl_weather_unit, LV_LABEL_PART_MAIN, &label_style3);
		lv_label_set_text(lbl_weather_unit, "°C");
		lv_obj_align(lbl_weather_unit, lbl_weather, LV_ALIGN_OUT_RIGHT_MID, 10, 0);

	} else {
		lv_label_set_text(lbl_cityname, cityname2);
		lv_label_set_text(lbl_weather, weachern);
		lv_obj_align(lbl_weather, lbl_cityname, LV_ALIGN_OUT_RIGHT_MID, 10, 0);
		lv_label_set_text(lbl_weather_unit, "°C");
		lv_obj_align(lbl_weather_unit, lbl_weather, LV_ALIGN_OUT_RIGHT_MID, 10, 0);
	}


	if (!scr2) { // bilibili粉丝
		scr2 = lv_obj_create(NULL, NULL);//在第二页创建
		scrs[scr_count++] = scr2;
		lv_obj_add_style(scr2, LV_BTN_PART_MAIN, &default_style);
		lv_obj_t* img4 = lv_img_create(scr2, NULL);
		// lv_img_set_src(img4, &logo);
		lv_img_set_src(img4, &coolflyreg_head);
		lv_obj_align(img4, NULL, LV_ALIGN_OUT_TOP_MID, 0, 240);
		lv_obj_t* img3 = lv_img_create(scr2, NULL);
		lv_img_set_src(img3, &huoj);
		lv_obj_align(img3, NULL, LV_ALIGN_OUT_BOTTOM_RIGHT, -5, -100);


		lv_style_init(&label_style);
		lv_style_set_text_opa(&label_style, LV_STATE_DEFAULT, LV_OPA_COVER);
		lv_style_set_text_color(&label_style, LV_STATE_DEFAULT, LV_COLOR_WHITE);
		lv_style_set_text_font(&label_style, LV_STATE_DEFAULT, &lv_font_montserrat_24);
		lbl_bili_name = lv_label_create(scr2, NULL);
		lv_obj_add_style(lbl_bili_name, LV_LABEL_PART_MAIN, &label_style);
		lv_label_set_text(lbl_bili_name, "- coolflyreg -");
		lv_obj_align(lbl_bili_name, NULL, LV_ALIGN_OUT_BOTTOM_LEFT, 30, -95);


		lv_style_init(&label_style2);
		lv_style_set_text_opa(&label_style2, LV_STATE_DEFAULT, LV_OPA_COVER);
		lv_style_set_text_color(&label_style2, LV_STATE_DEFAULT, LV_COLOR_WHITE);
		lv_style_set_text_font(&label_style2, LV_STATE_DEFAULT, &lv_font_montserrat_40);
		lbl_bili_fans = lv_label_create(scr2, NULL);
		lv_obj_add_style(lbl_bili_fans, LV_LABEL_PART_MAIN, &label_style2);
		lv_label_set_text(lbl_bili_fans, fens);
		lv_obj_align(lbl_bili_fans, lbl_bili_name, LV_ALIGN_OUT_BOTTOM_MID, 0, 10);
	} else {
		lv_label_set_text(lbl_bili_name, "- coolflyreg -");
		lv_label_set_text(lbl_bili_fans, fens);
	}


	if (!scr3) { // 数据监控
		scr3 = lv_obj_create(NULL, NULL);
		scrs[scr_count++] = scr3;
		lv_obj_add_style(scr3, LV_BTN_PART_MAIN, &default_style);
		lv_style_set_text_opa(&label_style4, LV_STATE_DEFAULT, LV_OPA_COVER);
		lv_style_set_text_color(&label_style4, LV_STATE_DEFAULT, LV_COLOR_WHITE);
		lv_style_set_text_font(&label_style4, LV_STATE_DEFAULT, &lv_font_montserrat_20);

		labe6 = lv_label_create(scr3, NULL);
		lv_obj_add_style(labe6, LV_LABEL_PART_MAIN, &label_style4);
		lv_label_set_text_fmt(labe6, "CPU Temp: %d °C", 0);
		lv_obj_set_pos(labe6, 2, 30);

		labe7 = lv_label_create(scr3, NULL);
		lv_obj_add_style(labe7, LV_LABEL_PART_MAIN, &label_style4);
		lv_label_set_text_fmt(labe7, "CPU Usage: %d\%", 0);
		lv_obj_set_pos(labe7, 2, 60);

		labe8 = lv_label_create(scr3, NULL);
		lv_obj_add_style(labe8, LV_LABEL_PART_MAIN, &label_style4);
		lv_label_set_text_fmt(labe8, "Mem Free: %d", freeHeap);
		lv_obj_set_pos(labe8, 2, 90);

		labe9 = lv_label_create(scr3, NULL);
		lv_obj_add_style(labe9, LV_LABEL_PART_MAIN, &label_style4);
		lv_label_set_text_fmt(labe9, "Net Upload: %dKB/s", 0);
		lv_obj_set_pos(labe9, 2, 120);

		labe10 = lv_label_create(scr3, NULL);
		lv_obj_add_style(labe10, LV_LABEL_PART_MAIN, &label_style4);
		lv_label_set_text_fmt(labe10, "Net Download: %dKB/s", 0);
		lv_obj_set_pos(labe10, 2, 150);
	} else {
		lv_label_set_text_fmt(labe6, "CPU Temp: %d °C", 0);
		lv_label_set_text_fmt(labe7, "CPU Usage: %d\%", 0);
		lv_label_set_text_fmt(labe8, "Mem Free: %d", freeHeap);
		lv_label_set_text_fmt(labe9, "Net Upload: %dKB/s", 0);
		lv_label_set_text_fmt(labe10, "Net Download: %dKB/s", 0);
	}

	if (!scr4) {
		scr4 = lv_obj_create(NULL, NULL);
		scrs[scr_count++] = scr4;
		lv_obj_add_style(scr4, LV_BTN_PART_MAIN, &default_style);
	}

	if (!scr5) {
		scr5 = lv_obj_create(NULL, NULL);
		scrs[scr_count++] = scr5;
		lv_obj_add_style(scr5, LV_BTN_PART_MAIN, &default_style);
	}

	if (!scr6) {
		scr6 = lv_obj_create(NULL, NULL);
		scrs[scr_count++] = scr6;
		lv_obj_add_style(scr6, LV_BTN_PART_MAIN, &default_style);
	}
}